<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>

<script>

  <!--  客户需求：先获取姓名，然后获取性别，然后获取年龄，最终将三个值拼接到一个数组当中-->

  //第一步，获取姓名
  function getUserName() {
    return new Promise((resolve, reject)=>{
      try {
        // throw Error('获取姓名失败!!')
        setTimeout(()=>{
          console.log('获取姓名成功~~')
          const user = {
            userName : 'wdh'
          }
          resolve(user)
        },1500)

      }catch (e){
        reject(e.message)
      }
    })
  }

  //  第二部 获取性别
  function getUserSex(user) {
    return new Promise((resolve, reject)=>{
      try {
        // throw Error('获取性别失败!!')
        setTimeout(()=>{
          console.log('获取性别成功~~')
          const sex = {
            sex : 'man'
          }
          resolve({
            ...user,
            ...sex
          })
        },1500)

      }catch (e){
        reject(e.message)
      }
    })
  }

  //获取年龄
  function getUserAge(sex) {
    return new Promise((resolve, reject)=>{
      try {
        // throw Error('获取年龄失败!!')
        setTimeout(()=>{
          console.log('获取年龄成功~~')
          const age = {
            age : 18
          }
          resolve({
            ...sex,
            ...age
          })
        },1500)

      }catch (e){
        reject(e.message)
      }
    })
  }



  async function getUserData() {
    const userName = await getUserName()
    const userSex = await getUserSex(userName)
    const userAge = await getUserAge(userSex)
    console.log('最终完整的数据',userAge)
  }
  //最终输出完整数据
  const result = getUserData()
  console.log('result',result)



</script>

</body>
</html>